package horde

import "event-chain/core/common"

type ISorter[T any] interface {
	common.IOnce
	Handle(T, T) bool
}

type Sorter[T any] struct {
	common.One
	handle func(T, T) bool
}

func NewSorter[T any](handle func(T, T) bool, isOnce bool) *Sorter[T] {
	res := &Sorter[T]{handle: handle}
	res.SetOnce(isOnce)
	return res
}

func (s *Sorter[T]) Handle(a T, b T) bool {
	return s.handle(a, b)
}
